package
{
	import flash.net.SharedObject;

	public class NinjaUserData
	{
		public var shared:SharedObject;

		public function NinjaUserData()
		{
			this.shared = SharedObject.getLocal("n_data");
			if (this.shared.data["wasCreated"] != 1)
			{
				this.shared.data["keyL"] = 37;
				this.shared.data["keyR"] = 39;
				this.shared.data["keyJ"] = 16;
				this.shared.data["username"] = "anon";
				this.shared.data["mission0ep"] = 0;
				this.shared.data["mission1ep"] = 10;
				this.shared.data["mission2ep"] = 20;
				this.shared.data["wasCreated"] = 1;
				this.shared.flush();
			}
		}

		public function NotifyEpisodeReached(num:uint):void
		{
			if (num < 10)
			{
				if (this.shared.data["mission0ep"] < num)
				{
					this.shared.data["mission0ep"] = num;
					this.shared.flush();
				}
			}
			else if (num < 20)
			{
				if (this.shared.data["mission1ep"] < num)
				{
					this.shared.data["mission1ep"] = num;
					this.shared.flush();
				}
			}
			else if (num < 30)
			{
				if (this.shared.data["mission2ep"] < num)
				{
					this.shared.data["mission2ep"] = num;
					this.shared.flush();
				}
			}
		}

		public function SetLeftKey(k:uint):void
		{
			this.shared.data["keyL"] = k;
			this.shared.flush();
			Main.getInstance().game.SetKeyDefs(this.shared.data["keyJ"], this.shared.data["keyL"], this.shared.data["keyR"]);
		}

		public function SetRightKey(k:uint):void
		{
			this.shared.data["keyR"] = k;
			this.shared.flush();
			Main.getInstance().game.SetKeyDefs(this.shared.data["keyJ"], this.shared.data["keyL"], this.shared.data["keyR"]);
		}

		public function SetJumpKey(k:uint):void
		{
			this.shared.data["keyJ"] = k;
			this.shared.flush();
			Main.getInstance().game.SetKeyDefs(this.shared.data["keyJ"], this.shared.data["keyL"], this.shared.data["keyR"]);
		}

		public function GetLeftKey():uint
		{
			return this.shared.data["keyL"];
		}

		public function GetRightKey():uint
		{
			return this.shared.data["keyR"];
		}

		public function GetJumpKey():uint
		{
			return this.shared.data["keyJ"];
		}

		public function GetEpisodeReached(setNum:uint):uint
		{
			if (setNum == 0)
			{
				return this.shared.data["mission0ep"];
			}
			if (setNum == 1)
			{
				return this.shared.data["mission1ep"];
			}
			if (setNum == 2)
			{
				return this.shared.data["mission2ep"];
			}
			return 0;
		}

		public function ValidateEpisodeReached(num:uint):Boolean
		{
			if (num < 10)
			{
				if (num <= this.shared.data["mission0ep"])
				{
					return true;
				}
			}
			else if (num < 20)
			{
				if (num <= this.shared.data["mission1ep"])
				{
					return true;
				}
			}
			else if (num < 30)
			{
				if (num <= this.shared.data["mission2ep"])
				{
					return true;
				}
			}
			else
			{
				return false;
			}
			return false;
		}
	}
}